<%@page import="com.fractalist.man.constants.ManConstants"%>
<%@page import="com.fractalist.base.core.constants.SystemConstants"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/includes.jsp"%>
<%
	pageContext.setAttribute("userTypeMap", ManConstants.USER_TYPE_MAP);
	pageContext.setAttribute("userGenderMap",
			ManConstants.USER_GENDER_MAP);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>用户</title>
<link rel="stylesheet" href="${ctx }/css/styles.css" type="text/css" />
<script type="text/javascript" src="${ctx }/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="${ctx }/js/jquery.form.js"></script>
<script>
	var userTypeMap = {};
	<c:forEach items="${userTypeMap}" var="entry">
	userTypeMap["${entry.key}"] = "${entry.value}";
	</c:forEach>
	var userGenderMap = {};
	<c:forEach items="${userGenderMap}" var="entry">
	userTypeMap["${entry.key}"] = "${entry.value}";
	</c:forEach>

	function createArticle() {
		var userName = $("#userName").val();
		var password = $("#password").val();
		var name = $("#name").val();
		var usertype = $("#usertype").val();
		var bust = $("#bust").val();
		var waistline = $("#waistline").val();
		var hip = $("#hip").val();
		var gender = $("#gender").val();
		var age = $("#age").val();
		var phoneNumber = $("#phoneNumber").val();
		if (userName == "") {
			alert("请输入账号");
			return;
		}
		/*if (password == "") {
			alert("请输入密码");
			return;
		}*/
		if (name == "") {
			alert("请输入昵称");
			return;
		}
		if (usertype == "") {
			alert("请选择用户类型");
			return;
		}
		if (gender == "") {
			alert("请输入性别");
			return;
		}
		if (age == "") {
			alert("请输入当前的年龄");
			return;
		}
		var pkBigImageUrl = !$("#pkBigImageUrl").find("img") ? "" : $("#pkBigImageUrl").find("img").attr("src");
		var imageUrl = !$("#imageUrl").find("img") ? "" : $("#imageUrl").find("img").attr("src");
		var pkImageUrl = !$("#pkImageUrl").find("img") ? "" : $("#pkImageUrl").find("img").attr("src");
		var jsonObj = {
			userId : $("#userId").val(),
			userName : userName,
			password : password,
			name : name,
			userType : usertype,
			bust : bust,
			waistline : waistline,
			hip : hip,
			gender : gender,
			age : age,
			phoneNumber : phoneNumber,
			imageUrl : imageUrl,
			pkImageUrl : pkImageUrl,
			pkBigImageUrl : pkBigImageUrl
		};
		
		var createDate = $("#createDate").val();
		var score = $("#score").val();
		var girlWeight = $("#girlWeight").val();
		var girlPkWeight = $("#girlPkWeight").val();
		if (createDate != "") {
			if (!/^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$/
					.test(createDate)) {
				alert("日期的格式错误，请填写并保证yyyy-MM-dd HH:mm格式");
				return;
			}
			jsonObj["createDate"] = createDate;
		}
		if (score != "") {
			if (!/^[0-9]+$/.test(score)) {
				alert("积分必须为数字，且为正整数");
				return;
			}
			jsonObj["score"] = score;
		}
		if (girlWeight != "") {
			if (!/^[0-9]+$/.test(girlWeight)
					&& !/^[0-9]+\.\d{1,2}$/.test(girlWeight)) {
				alert("投票加权值必须为正整数或两位小数");
				return;
			}
			jsonObj["girlWeight"] = girlWeight;
		}
		if (girlPkWeight != "") {
			if (!/^[0-9]+$/.test(girlPkWeight)
					&& !/^[0-9]+\.\d{1,2}$/.test(girlPkWeight)) {
				alert("pk加权值必须为正整数或两位小数");
				return;
			}
			jsonObj["girlPkWeight"] = girlPkWeight;
		}
		$.post("${ctx}/manager/modifyUser.action", jsonObj, function(data) {
			data = eval("(" + data + ")");
			if (data.state != 0) {
				alert(data.msg);
			} else {
				alert(data.msg);
				var urls = "${ctx}/manager/viewUserPage.action";
				<c:if test="${!empty zhuangnvlangList}">
				urls = "${ctx}/manager/viewUserZhuangnvlangPage.action";
				</c:if>
				location.href = urls;
			}
		})
	}
</script>
</head>
<body style="overflow-y: scroll;">
	<div id="wrapper">
		<div id="content_wrap">
			<div class="tabs_content">
				<div class="active_tab" id="tab1"></div>
				<div id="table_wrapper" style="width: 100%; overflow: auto;">
					<input type="hidden" id="userId" value="${modifyUser.userId }" />
					<table class="table" cellpadding="0" cellspacing="0">
						<tr>
							<td>账号</td>
							<td><input id="userName" name="userName"
								value="${modifyUser.userName }" /></td>
						</tr>
						<tr>
							<td>密码</td>
							<td><input id="password" name="password"
								value="${modifyUser.password }" type="password" /></td>
						</tr>
						<tr>
							<td>昵称</td>
							<td><input id="name" name="name" value="${modifyUser.name }" /></td>
						</tr>
						<tr>
							<td>类型</td>
							<td><select id="usertype">
									<c:forEach items="${userTypeMap}" var="entry">
										<option value="${entry.key}"
											<c:if test="${entry.key == modifyUser.groupId }">selected="selected"</c:if>>${entry.value}</option>
									</c:forEach>
							</select></td>
						</tr>
						<tr>
							<td>胸围</td>
							<td><input id="bust" name="bust" value="${modifyUser.bust }" /></td>
						</tr>
						<tr>
							<td>腰围</td>
							<td><input id="waistline" name="waistline" value="${modifyUser.waistline }" /></td>
						</tr>
						<tr>
							<td>臀围</td>
							<td><input id="hip" name="hip" value="${modifyUser.hip }" /></td>
						</tr>
						<tr>
							<td>性别</td>
							<td><select id="gender">
									<c:forEach items="${userGenderMap}" var="entry">
										<option value="${entry.key}"
											<c:if test="${entry.key == modifyUser.gender }">selected="selected"</c:if>>${entry.value}</option>
									</c:forEach>
							</select></td>
						</tr>
						<tr>
							<td>年纪</td>
							<td><input id="age" name="age" value="${modifyUser.age }" /></td>
						</tr>
						<tr>
							<td>手机号</td>
							<td><input id="phoneNumber" name="phoneNumber"
								value="${modifyUser.phoneNumber }" /></td>
						</tr>
						<tr
							<c:if test="${empty modifyUser || empty modifyUser.score }">style="display:none"</c:if>>
							<td>积分</td>
							<td><input id="score" name="score"
								value="${modifyUser.score }" /></td>
						</tr>
						<tr
							<c:if test="${empty modifyUser || empty modifyUser.createDate }">style="display:none"</c:if>>
							<td>注册日期</td>
							<td><input id="createDate" name="createDate"
								value='<fmt:formatDate value="${modifyUser.createDate}" pattern="yyyy-MM-dd HH:mm"/>' /><font
								color=red>*保证yyyy-MM-dd HH:mm格式</font></td>
						</tr>
						<tr>
							<td>投票加权值</td>
							<td><input id="girlWeight" name="girlWeight"
								value='<c:if test="${empty modifyUser.girlWeight }">1.0</c:if><c:if test="${!empty modifyUser.girlWeight }">${modifyUser.girlWeight }</c:if>' /></td>
						</tr>
						<tr>
							<td>pk加权值</td>
							<td><input id="girlPkWeight" name="girlPkWeight"
								value='<c:if test="${empty modifyUser.girlPkWeight }">1.0</c:if><c:if test="${!empty modifyUser.girlPkWeight }">${modifyUser.girlPkWeight }</c:if>' /></td>
						</tr>

						<tr>
							<td>上传头像大图片</td>
							<td><form id="uploadForm2" method="post"
									enctype="multipart/form-data">
									<table>
										<tr>
											<td><input id="fileid" type="file" value="选择上传图片"
												name="fujianFile" onchange="uploadImage2()" /><font
												id="imageUrl"><c:if test="${!empty modifyUser.imageUrl }"><img src="${modifyUser.imageUrl }"/></c:if></font><font color="red">*上传图片需要一点时间，请耐心等待</font>
											</td>
										</tr>
									</table>
								</form></td>
						</tr>
						<tr>
							<td>上传装女郎pk小图片</td>
							<td><form id="uploadForm3" method="post"
									enctype="multipart/form-data">
									<table>
										<tr>
											<td><input id="fileid" type="file" value="选择上传图片"
												name="fujianFile" onchange="uploadImage3()" /><font
												id="pkImageUrl"><c:if test="${!empty modifyUser.pkImageUrl }"><img src="${modifyUser.pkImageUrl }"/></c:if></font><font color="red">*上传图片需要一点时间，请耐心等待</font>
											</td>
										</tr>
									</table>
								</form></td>
						</tr>
						<tr>
							<td>上传装女郎pk大图片</td>
							<td><form id="uploadForm4" method="post"
									enctype="multipart/form-data">
									<table>
										<tr>
											<td><input id="fileid" type="file" value="选择上传图片"
												name="fujianFile" onchange="uploadImage4()" /><font
												id="pkBigImageUrl"><c:if test="${!empty modifyUser.pkBigImageUrl }"><img src="${modifyUser.pkBigImageUrl }"/></c:if></font><font color="red">*上传图片需要一点时间，请耐心等待</font>
											</td>
										</tr>
									</table>
								</form></td>
						</tr>
						<tr>
							<td></td>
							<td><input type="button" value="创建"
								onclick="createArticle();" /></td>
						</tr>
					</table>
				</div>
			</div>
		</div>
	</div>


	<script>
	function uploadImage4() {
		var options = {
			url : '${ctx}/manager/uploadImgBase.action',
			type : "POST",
			dataType : "json",
			success : function(result) {
				var code = result.data.code;
				var url = result.data.url;
				if (code == 0) {
					$("#pkBigImageUrl").html("<img src='" + url + "' />");
				}
			}
		};
		$("#uploadForm4").ajaxSubmit(options);
	}
	
	function uploadImage3() {
		var options = {
			url : '${ctx}/manager/uploadImgBase.action',
			type : "POST",
			dataType : "json",
			success : function(result) {
				var code = result.data.code;
				var url = result.data.url;
				if (code == 0) {
					$("#pkImageUrl").html("<img src='" + url + "' />");
				}
			}
		};
		$("#uploadForm3").ajaxSubmit(options);
	}
	
	
	function uploadImage2() {
		var options = {
			url : '${ctx}/manager/uploadImgBase.action',
			type : "POST",
			dataType : "json",
			success : function(result) {
				var code = result.data.code;
				var url = result.data.url;
				if (code == 0) {
					$("#imageUrl").html("<img src='" + url + "' />");
				}
			}
		};
		$("#uploadForm2").ajaxSubmit(options);
	}
	
	function uploadImage() {
		var options = {
			url : '${ctx}/manager/uploadImgBase.action',
			type : "POST",
			dataType : "json",
			success : function(result) {
				var code = result.data.code;
				var url = result.data.url;
				if (code == 0) {
					$("#iconUrl").html("<img src='" + url + "' />");
				}
			}
		};
		$("#uploadForm1").ajaxSubmit(options);
	}
	</script>
</body>
</html>

